﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VideoClassLibrary.Model;
using VideoClassLibrary.BusinessLogicLayer;
public partial class ClassRoomManagement_SearchRoomList : AdminUserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    public void Bind()
    {
        DataSet ds=new DataSet();
        ClassRoomModule cm = new ClassRoomModule();
        if (this.SchoolID == 0)
        {

            ds = cm.GetAllRoom();
        }
        else
        {
            ds = cm.GetRoomListByWhereAndSID(" and IsPublished=1", this.SchoolID); 
        }
        Repeater1.DataSource =  getPage(ds);
        Repeater1.DataBind();
    }

    protected void BtCheck_Click(object sender, EventArgs e)
    {
        
        string name = TxtCheckRoom.Text.Trim();
        if (name == "" || name== null)
        {
            Bind();
        }
        else
        {
            CheckBind(name);
        }
    }
    public void CheckBind(string name)
    {
        ClassRoomModule cm = new ClassRoomModule();
        DataSet ds = new DataSet();
        if (this.SchoolID == 0)
        {
            ds = cm.QueryByRoomname(name);

        }
        else
        {
            string where = " and  VR_roomName  like '%" + name + "%' and IsPublished=1";
            ds = cm.GetRoomListByWhereAndSID(where, this.SchoolID);
        }
        Repeater1.DataSource = getPage(ds);
        Repeater1.DataBind();
    }
    public string GetSchNameByID(int schid)
    {
        TeacherModule ta = new TeacherModule();
        string name = ta.GetSchNameByID(schid);
        return name;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddClassRoom.aspx");
    }
    public PagedDataSource getPage(DataSet ds)
    {
        this.pager.RecordCount = ds.Tables[0].Rows.Count;
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = pager.CurrentPageIndex - 1;
        pds.PageSize = pager.PageSize;
        return pds;
    }
    protected void pager_PageChanged(object sender, EventArgs e)
    {
        string name = TxtCheckRoom.Text.Trim();
        if (name == "" || name == null)
        {
            Bind();
        }
        else
        {
            CheckBind(name);
        }
    }
    public void btnUpdate_Click(object sender, CommandEventArgs e)
    {
        Response.Redirect("UpdateRoom.aspx?RID="+e.CommandArgument.ToString());
    }

   
}
